﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Diagonal.Biztalk.SchemaExplorer
{
    public class GetSchemaHandler : IHttpHandler 
    {

        

        #region IHttpHandler Members
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            var getSchema = new GetSchema();

            string[] parts = context.Request.AppRelativeCurrentExecutionFilePath.Split('/');
            string version = "";
            if (parts.Length > 3)
            {
                // we have a version 
                version = parts[2];
            }

            var xmlstring = getSchema.GetSchemaText(Path.GetFileName(context.Request.Url.AbsolutePath), version);            
            xmlstring = xmlstring.Replace("utf-16", "utf-8");
            context.Response.Write(xmlstring);
            
            
        }
        #endregion

        private IEnumerable<string> GetTestAssemblys()
        {
            yield return "NYCC, Version=1.0.0.1, Culture=neutral, PublicKeyToken=6957b5909d4d2938";
            yield return "NYCC, Version=1.0.0.2, Culture=neutral, PublicKeyToken=6957b5909d4d2938";
        }


    }
}
